import java.util.ArrayList;

import javax.swing.ImageIcon;


public class Bishop extends Piece
{
	public Bishop()
	{
		super();
	}
	public Bishop(int x, int y, boolean isWhite)
	{
		super(x, y, isWhite);
		updateImage();
	}
	
	public void updateImage()
	{
		if(isBackgroundWhite())
		{
			if(isWhite() == true)
			{
				setImage(new ImageIcon("images/whiteBishopWhite.gif", ""));
			}
			else
			{
				setImage(new ImageIcon("images/blackBishopWhite.gif", ""));
			}
		}
		else
		{
			if(isWhite() == true)
			{
				setImage(new ImageIcon("images/whiteBishopBlack.gif", ""));
			}
			else
			{
				setImage(new ImageIcon("images/blackBishopBlack.gif", ""));
			}
		}
		if(isHighlightedRed())
		{
			highlightRed();
		}
	}

	public void highlightRed()
	{
		if(isWhite())
		{
//			System.out.println("I am the white Tiger");
			setImage(new ImageIcon("images/whiteBishopRed.gif", ""));
			setIsHighlightedRed(true);
		}
		else
		{
//			System.out.println("I am the black Tiger");
			setImage(new ImageIcon("images/blackBishopRed.gif", ""));
			setIsHighlightedRed(true);
		}
	}
	public void deHighlight()
	{
		updateImage();
		setIsHighlightedRed(false);
	}
	
	public void addDiagonalMoves(ArrayList<Location> list, Spot[][] spot)
	{
		int y;
		y = getY()+1;
		for(int x = getX()+1; x < 8 && y < 8; x++)
		{
			if(!(spot[x][y].getPiece() instanceof Empty))
			{
				if(spot[x][y].getPiece().isWhite() != isWhite())
				{
					list.add(new Location(x, y));
				}
				break;
			}
			list.add(new Location(x, y));
			y++;
		}
		y = getY()-1;
		for(int x = getX()+1; x < 8 && y >= 0; x++)
		{
			if(!(spot[x][y].getPiece() instanceof Empty))
			{
				if(spot[x][y].getPiece().isWhite() != isWhite())
				{
					list.add(new Location(x, y));
				}
				break;
			}
			list.add(new Location(x, y));
			y--;
		}
		
		y = getY()+1;
		for(int x = getX()-1; x >= 0 && y < 8; x--)
		{
			System.out.println("WELCOME TO THE BISHOP DIAGONAL");
			if(!(spot[x][y].getPiece() instanceof Empty))
			{
				if(spot[x][y].getPiece().isWhite() != isWhite())
				{
					list.add(new Location(x, y));
				}
				break;
			}
			System.out.println("Adding" + x + "," + y);
			list.add(new Location(x, y));
			y++;
		}
		y = getY()-1;
		for(int x = getX()-1; x >= 0 && y >= 0; x--)
		{
			System.out.println("WELCOME TO THE BISHOP DIAGONAL");
			if(!(spot[x][y].getPiece() instanceof Empty))
			{
				if(spot[x][y].getPiece().isWhite() != isWhite())
				{
					list.add(new Location(x, y));
				}
				break;
			}
			System.out.println("Adding" + x + "," + y);
			list.add(new Location(x, y));
			y--;
		}
	}
	
	public ArrayList<Location> getPossibleMoves(Spot[][] spot)
	{
		ArrayList<Location> list = new ArrayList<Location>();
		
		addDiagonalMoves(list, spot);
		
		removeOutOfBounds(list);
		removeSameColor(list, spot);
		return list;
		
	}
}
